package com.yxuan.springboot.service.impl;

import com.yxuan.springboot.mapper.AllProfessionalMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.yxuan.springboot.model.AllProfessional;
import com.yxuan.springboot.service.AllProfessionalService;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * 
 * @author zchao
 *    AllProfessional业务层实现类
 * @date 2023-05-18 20:19:29
 */
@Service
@Transactional
public class AllProfessionalServiceImpl extends BaseServiceImpl<AllProfessional> implements AllProfessionalService {

    @Autowired
    private AllProfessionalMapper allProfessionalMapper;

    @Override
    public Map<String, Object> findAllProfessionalMajor(String educationLevel) {
//        主map
        Map<String,Object> map = new HashMap<>();
//        加入map的列表
        ArrayList<Map<String, Object>> arrayListMain = new ArrayList<>();
//        查询专业主要大类
        List<AllProfessional> list = allProfessionalMapper.getMajorType(educationLevel);
//        循环查找 大类里面的细类
        for (AllProfessional allProfessional : list){
//            map2
            Map<String,Object> map2 = new HashMap<>();
//            取得id
            map2.put("id",allProfessional.getId());
//            获取专业大类
            map2.put("typeName",allProfessional.getMajorType());
            String majorType = allProfessional.getMajorType();
//            根据专业大类获取 专业细类
            List<AllProfessional> listItem = allProfessionalMapper.getMajorDetailType(majorType);
//            获取细类的总数
            map2.put("totalNumber",listItem.size());
//            新建列表，填入 已完善的细类以及专业信息
            ArrayList<Map<String, Object>> arrayList = new ArrayList<>();
//            循环查找 细类的专业名称
            for (AllProfessional allProfessionalItem : listItem){
                Map<String,Object> mapItem = new HashMap<>();
                mapItem.put("id",allProfessionalItem.getId());
//                获取细类的名称
                String detailTypeName =allProfessionalItem.getMajorDetailType();
                mapItem.put("detailTypeName",detailTypeName);
//                根据专业细类 查询 细类的专业信息
                List<AllProfessional> listItem_2 = allProfessionalMapper.getProfessionalByType(detailTypeName,educationLevel);
                mapItem.put("majorLength",listItem_2.size());
//                新建列表 填入专业信息
                ArrayList<Map<String, Object>> arrayList2 = new ArrayList<>();
//                循环专业信息，填入列表
                for (AllProfessional allProfessionalItem_2 : listItem_2){
                    Map<String,Object> mapItem_2 = new HashMap<>();
                    mapItem_2.put("id",allProfessionalItem_2.getId());
                    mapItem_2.put("majorName",allProfessionalItem_2.getName());
                    mapItem_2.put("studyLength",allProfessionalItem_2.getStudyLength());
                    arrayList2.add(mapItem_2);
                }
//                将对应的专业信息填入 arrayList2
                mapItem.put("majorList",arrayList2);
//                将对应的 已完善的细类信息填入列表 arrayList
                arrayList.add(mapItem);
            }
            map2.put("datailType",arrayList);
            arrayListMain.add(map2);
        }
        map.put("list",arrayListMain);
        return map;
    }
}
